package com.REPDPMSystem.Controller;

import com.REPDPMSystem.Service.CustomerService;
import com.REPDPMSystem.Utils.R;
import com.REPDPMSystem.Entity.Customer;
import com.alibaba.fastjson2.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class CustomerController {
    @Autowired
    CustomerService customerService;
    //OK
    @CrossOrigin
    @PostMapping("/POST/CreateCustomerInfo")
    public R createCustomerInfo(@RequestBody Customer customer){
        return customerService.createCutomerInfo(customer)?R.ok():R.error().message("创建客户信息失败！");
    }
    //OK
    @CrossOrigin
    @PostMapping("/POST/ChangeCustomerInfo")
    public R changeCustomerInfo(@RequestBody Customer customer){
        return customerService.changeCutomerInfo(customer)?R.ok():R.error().message("修改客户信息失败！");
    }
    //OK
    @CrossOrigin
    @GetMapping("/GET/CustomerInfo")
    public R getCustomerInfo(){
        return R.ok().data("CustomerInfoList",new JSONArray(customerService.getCutomerInfo()));
    }
    //OK
    @CrossOrigin
    @GetMapping("/GET/CustomerInfoByName")
    public R getCustomerInfoByName(@RequestParam(value = "customer_name")String customer_name){
        return R.ok().data("CustomerInfoList",new JSONArray(customerService.getCutomerInfo(customer_name)));
    }
    //OK
    @CrossOrigin
    @GetMapping("/GET/CustomerInfoBy23")
    public R getCustomerInfo23(@RequestParam(value = "organizationI")String organizationI,@RequestParam(value = "organizationII")String organizationII){
        //System.out.println(organizationI);
        //System.out.println(organizationII);
        return R.ok().data("CustomerInfoList",new JSONArray(customerService.getCustomerInfo(organizationI,organizationII)));
    }

}
